#ifndef MULT_LIDAR_HPP
#define MULT_LIDAR_HPP

#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <geometry_msgs/msg/point_stamped.hpp>
#include <std_msgs/msg/header.hpp> 
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <memory>
#include <tf2_ros/static_transform_broadcaster.h>
#include <tf2_ros/transform_broadcaster.h>

#include "mult_lidar/pointcloud_processor.hpp"
#include "mult_lidar/detection_manager.hpp"
#include "mult_lidar/barrel_detector.hpp"
#include "mult_lidar/manhole_detector.hpp"
#include "mult_lidar/neutron_detector.hpp"
#include "mult_lidar/merged_cloud.hpp"


namespace mult_lidar {

    class MultLidarNode : public rclcpp::Node,  public std::enable_shared_from_this<MultLidarNode>
    {

    public:
    
        MultLidarNode();


    private:

        void declare_parameters();
        void init_components();
        void setup_ros_interface();

        void cloud_callback(const sensor_msgs::msg::PointCloud2::SharedPtr msg);
        void process_pointcloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
        //void publish_pointcloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud,
        //                        const std_msgs::msg::Header& header);
        void publish_pointcloud(const std_msgs::msg::Header& header);
        void perform_detection();
        void publish_static_tf();
        void declare_tf_parameters();

        //声明点云叠加成员变量
        int merged_max_frames_;
        bool enable_merged_cloud_publish_;
        int publish_frequency_;

        //点云数据
        //pcl::PointCloud<pcl::PointXYZI>::Ptr accumulated_cloud_;
        std::unique_ptr<Merged_cloud> merged_cloud_;

        //检测器模式选择
        std::string detection_mode_;


        //tf成员变量
        std::shared_ptr<tf2_ros::StaticTransformBroadcaster> static_tf_broadcaster_;
        
        std::string lidar_frame_;
        std::string base_frame_;
        bool publish_tf_;
        bool tf_initialized_ = false;
        


        //ROS接口
        rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr cloud_sub_;
        //rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_cloud_;
        rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_accumulated_cloud_;
        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_center_;
        rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_ring_cloud_;
        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_handle_center_;
        rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pub_handle_cloud_;
        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_neutron_center_;

        
        //处理接口
        std::unique_ptr<PointCloudProcessor> processor_;
        std::unique_ptr<DetectionManager> detection_manager_;


        

    };


}

#endif